﻿import mx.utils.Delegate;

import com.gamemeal.ui.IButtonElement;
import com.mixmedia.mx.AbstractEventDispatcher;
import com.mixmedia.mx.events.EventButton;

/**
 * @author Colin
 */
class com.gamemeal.ui.ButtonClip extends AbstractEventDispatcher {
	public function ButtonClip(btn:Object){
		btn.onPress = Delegate.create(this,press);
		btn.onRelease = Delegate.create(this,release);
		btn.onRollOver = Delegate.create(this,over);
		btn.onRollOut = Delegate.create(this,out);
	}

	private function press(){
		dispatchEvent(new EventButton(this,EventButton.EVENTPRESS));
	}
	
	private function release(){
		dispatchEvent(new EventButton(this,EventButton.EVENTRELEASE));
	}

	private function over(){
		dispatchEvent(new EventButton(this,EventButton.EVENTROLLOVER));
	}

	private function out(){
		dispatchEvent(new EventButton(this,EventButton.EVENTROLLOUT));
	}

	public function addElements(element:IButtonElement):Void{
		this.addEventListener(EventButton.EVENTROLLOVER,Delegate.create(element,element.onOver));
		this.addEventListener(EventButton.EVENTROLLOUT,Delegate.create(element,element.onOut));
		this.addEventListener(EventButton.EVENTRELEASE,Delegate.create(element,element.onClick));
		this.addEventListener(EventButton.EVENTRESET,Delegate.create(element,element.onReset));
	}
}